import { createRouter, createWebHistory } from 'vue-router'
const Home =  () => import('../views/home/Home')
const Categroy =  () => import( '../views/category/Categroy')
const Detail =  () => import( '../views/detail/Detail')
// import Detail from '../views/detail/Detail.vue'
const Profile =  () => import( '../views/profile/Profile')
const ShopCart =  () => import( '../views/shopcart/ShopCart')

const routes = [

  {
    path: '',
    name: 'DefaultHome',
    component: Home,
    meta:{
      title:'首页-＋'
    }
  },
  {
    path: '/',
    name: 'home',
    component: Home,
    meta:{
      title:'首页-＋'
    }
  },
  {
    path: '/category',
    name: 'Category',
    component: Categroy,
    meta:{
      title:'分类'
    }
  },
  {
    path: '/detail',
    name: 'Detail',
    component: Detail,
    meta:{
      title:'详情'
    }
  },
  {
    path: '/profile',
    name: 'Profile',
    component:Profile,
    meta:{
      title:'个人中心'
    }
  },
  {
    path: '/shopCart',
    name: 'ShopCart',
    component:ShopCart,
    meta:{
      title:'购物车'
    }
  },


]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

router.beforeEach((to ,from,next)=>{
  //如果没有登录、从这里到登录页面
  next();
  document.title = to.meta.title;
})

export default router

